|
|
|
|
|
|
|
able to see which colors it has loaded into the system palette. For example, an image may define 200 colors in its logical color palette but display only 100 of them. PalWatch lets you see the other colors even if they are not displayed. |
|
|
|
|
|
|
|
|
Learning the System Palette Mapping |
|
|
|
|
|
|
|
|
The system palette is maintained by the palette manager, and you have little control over how it does its job. The way colors are added to the system palette depends on the colors that are already there, the flags set for the colors (for example, PC_NOCOLLAPSE), and the other applications that are running. In general, it is difficult for you to force your logical palette entries into the system palette in any particular positions. It's even hard to determine after the fact where your logical palette entries were placed. Both of these tasks are possible, however. |
|
|
|
|
|
|
|
|
You can determine the location of your logical colors by using the PSet method and the GetBitmapBits API function. GetBitmapBits lets you examine the system palette indexes of the pixels that make up an image. The function takes as parameters a handle to a bitmap, the number of bytes of information you want to retrieve, and an array of bytes. |
|
|
|
|
|
|
|
|
If you set the AutoRedraw property of a form or picture box to true, that object's Image property gives a handle to the object's persistent bitmap. You can use that handle in calls to GetBitmapBits. The function places the system palette indexes of the pixels in the byte array and returns the number of bytes it fetched. If the function fails, it returns the value zero. |
|
|
|
|
|
|
|
|
Using GetBitmapBits, you can determine how your logical palette has been mapped into the system palette. For each color in the logical palette, use the PSet method to set the color of the pixel in the upper-left corner of the image. Specify the color of the pixel using its logical palette index. |
|
|
|
|
|
|
|
|
Then use GetBitmapBits to retrieve the system palette index of that pixel. This tells you how your logical palette index mapped into the system palette. The following code uses this technique to show where each logical palette entry is mapped. |
|
|
|
 |
|
|
|
|
' Display a list of the colors in the logical
' palette and how they map to the system palette. Private Sub ShowEntries()
Dim num_entries As Long
Dim palentry(0 To 255) As PALETTEENTRY
Dim pixel As Byte
Dim orig_color As Long
Dim i As Integer
Dim txt As String
If picCanvas.Picture = 0 Then
txtPositions.Text = "No picture loaded."
Exit Sub
ElseIf picCanvas.Picture.hPal = 0 Then
txtPositions.Text = "Default palette." |
|
|
|
|
|